﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using QAAdmin.BusinessObject;
using System.Linq;

namespace QAAdmin.UI
{
    public partial class MainForm : BaseFormWithHeader
    {
        private IList<QAJob> lstQAJob;

        public MainForm()
        {
            InitializeComponent();
        }

        private void Initialize()
        {
            this.Hide();
            this.lblMonitor.Text = "List Penugasan";
            tabControl1.TabPages.Remove(tbpQAJob);
            tabControl1.TabPages.Remove(tbpReport);
            tabControl1.TabPages.Remove(tbpUser);

            frmLogin f = new frmLogin();
            System.Windows.Forms.DialogResult result = f.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.Cancel)
                Application.Exit();
            else
                this.Text += " (" + QAController.Username + ")";

            if (QAController.UserRole == TipeUSER.Supervisor)
            {
                lblFormName.Text = "Quality Assurance Supervisor (" + QAController.TipeSPT + ")";
                tabControl1.TabPages.Add(tbpQAJob);
                tabControl1.TabPages.Add(tbpReport);
                PopulateFilter();
            }
            else if (QAController.UserRole == TipeUSER.Administrator)
            {
                tabControl1.TabPages.Add(tbpUser);
            }
            
            this.dgvJob.DataSource = null;
            this.dgvJob.Rows.Clear();
            this.Show();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            Initialize();
            tbpUser.Enter += new EventHandler(tbpEnter_Click);
        }

        void tbpEnter_Click(object sender, EventArgs e)
        {
            RefreshDataGridUser();
        }

        private void cmbTipe_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                dgvJob.Rows.Clear();
                PopulateFilter();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void PopulateFilter()
        {
            cmbPetugas.DataSource = null; 
            cmbPetugas.Items.Clear();            

            List<Petugas> lstPetugas = new List<Petugas>();
            Petugas p = new Petugas();
            p.Username = "all";
            lstPetugas.Add(p);
            if (QAController.TipeSPT == TipeSPT.Balance)
            {
                lstPetugas.AddRange(QAController.GetBalancedPetugas());
                lstPetugas.AddRange(QAController.GetOfflinePetugasBalance());
                cmbPetugas.DataSource = lstPetugas;
                cmbPetugas.DisplayMember = "Username";
            }
            else
            {
                lstPetugas.AddRange(QAController.GetUnbalancedPetugas());
                lstPetugas.AddRange(QAController.GetOfflinePetugasUnBalance());
                cmbPetugas.DataSource = lstPetugas;
                cmbPetugas.DisplayMember = "Username";
            }
            List<QAStatus> lstQAStatus = Enum.GetValues(typeof(QAStatus)).Cast<QAStatus>().ToList<QAStatus>();
            //lstQAStatus.Remove(QAStatus.none);
            cmbStatus.DataSource = lstQAStatus;
        }

        private void PopulateDataGrid()
        {
            dgvJob.Rows.Clear();
            string petugas = string.Empty;
            string status = string.Empty;
            petugas = cmbPetugas.Text.Equals("all") ? "%" : cmbPetugas.Text;
            if (cmbStatus.Text.Equals("all"))
                status = "%";
            else if (cmbStatus.Text.Equals("none"))
                status = string.Empty;
            else
                status = cmbStatus.Text;

            lstQAJob = QAController.GetJobByPetugasAndStatus(petugas, status);

            foreach (QAJob job in lstQAJob)
            {
                string waktuPengecekan = job.StatusAkhir.Length == 0 ? "" : job.WaktuPengecekan.ToString("dd MMM yyyy HH:mm:ss");
                object[] values = { job.DocId, job.Barcode, job.JenisSPT, job.NamaPTKP, job.Npwp, job.MasaPajak, 
                                      job.WaktuPenugasan.ToString("dd MMM yyyy HH:mm:ss"), job.DitugaskanKepada, waktuPengecekan, job.StatusAkhir, job.Catatan, job.JumlahPerbaikan };
                dgvJob.Rows.Add(values);
            }

            //--added by Vincent 20130110 for row number--
            //dgvJob.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders; 
            /*int rowNumber = 1;
            foreach (DataGridViewRow row in dgvJob.Rows)
            {
                if (row.IsNewRow) continue;
                row.HeaderCell.Value = "" + rowNumber;
                rowNumber = rowNumber + 1;
            }
            dgvJob.RowHeadersWidth = 50;*/
            //dgvJob.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);  
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                lblMonitor.Text = "List Penugasan";
                PopulateDataGrid();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void btnDetail_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgvJob.SelectedRows.Count == 0)
                {
                    MessageBox.Show("Tidak ada data yang dipilih", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                //else if added by Vincent 20130204 for handling update exception in copy all grid rows to excel---------------------
                else if (dgvJob.SelectedRows.Count > 1)
                {
                    MessageBox.Show("Pilih hanya satu data yang akan dilihat", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                //-------------------------------------------------------------------------------------------------------------------

                string docId = dgvJob.SelectedRows[0].Cells[0].Value.ToString();
                string barcode = dgvJob.SelectedRows[0].Cells[1].Value.ToString();
                
                QAJob job = QAController.GetJobByDocIdAndBarcode(docId, barcode);
                QAController.Job = job;

                frmJobDetails f = new frmJobDetails();
                f.lblFormName.Text = "Formulir "+job.JenisSPT;
                f.txtDocId.Text = job.DocId;
                f.txtNama.Text = job.NamaPTKP;
                f.txtNPWP.Text = job.Npwp;
                f.txtMasaPajak.Text = job.MasaPajak;
                f.txtWaktuPenugasan.Text = job.WaktuPenugasan.ToString("dd MMM yyyy HH:mm:ss");
                f.txtStatusAwal.Text = job.StatusAsal;
                f.txtWaktuPengecekan.Text = job.WaktuPengecekan.ToString("dd MMM yyyy HH:mm:ss");
                f.txtStatusAkhir.Text = job.StatusAkhir;
                f.txtCatatan.Text = job.Catatan;
                f.txtPetugas.Text = job.DitugaskanKepada;
                f.txtBarcode.Text = job.Barcode;
                f.txtJumlahPerbaikan.Text = job.JumlahPerbaikan;
                f.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btnBuatPenugasan_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                frmPenugasan f = new frmPenugasan(frmPenugasan.Mode.New);
                f.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void btnRefreshUser_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                RefreshDataGridUser();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void RefreshDataGridUser()
        {
            dgvUser.Rows.Clear();

            IList<Petugas> lstPetugas = QAController.GetAllPetugas();
            foreach (Petugas p in lstPetugas)
            {
                object[] values = { p.Username, p.Group, p.IsLogin };
                dgvUser.Rows.Add(values);
            }

            //--added by Vincent 20130110 for row number--
            //dgvUser.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders; 
            /*int rowNumber = 1;
            foreach (DataGridViewRow row in dgvUser.Rows)
            {
                if (row.IsNewRow) continue;
                row.HeaderCell.Value = "" + rowNumber;
                rowNumber = rowNumber + 1;
            }
            dgvUser.RowHeadersWidth = 50;*/
            //dgvUser.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);  
        }

        private void btnTambah_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                frmUser f = new frmUser(frmUser.Mode.New);
                f.ShowDialog();

                RefreshDataGridUser();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void btnHapus_Click(object sender, EventArgs e)
        {
            if (dgvUser.SelectedRows.Count == 0)
            {
                MessageBox.Show("Tidak ada data yang dipilih", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //else if added by Vincent 20130204 for handling update exception in copy all grid rows to excel---------------------
            else if (dgvUser.SelectedRows.Count > 1)
            {
                MessageBox.Show("Pilih hanya satu data yang akan diubah", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //-------------------------------------------------------------------------------------------------------------------

            string username = dgvUser.SelectedRows[0].Cells[0].Value.ToString();
            if (username == QAController.Username)
            {
                MessageBox.Show("Anda tidak bisa menghapus account Anda sendiri", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (QAController.DoesUserHaveQAJob(username))
            {
                MessageBox.Show("Anda tidak bisa menghapus \"" + username + "\" karena user tersebut telah ditugaskan untuk mengerjakan QA Job", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string msg = "Anda yakin akan menghapus user \"" + username + "\"?";
            if (MessageBox.Show(msg, this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.No)
                return;

            try
            {
                this.Cursor = Cursors.WaitCursor;
                QAController.HapusPetugas(username);
                RefreshDataGridUser();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void btnUbah_Click(object sender, EventArgs e)
        {
            if (dgvUser.SelectedRows.Count == 0)
            {
                MessageBox.Show("Tidak ada data yang dipilih", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //else if added by Vincent 20130204 for handling update exception in copy all grid rows to excel---------------------
            else if (dgvUser.SelectedRows.Count > 1)
            {
                MessageBox.Show("Pilih hanya satu data yang akan diubah", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //-------------------------------------------------------------------------------------------------------------------

            string username = dgvUser.SelectedRows[0].Cells[0].Value.ToString();
            string group = dgvUser.SelectedRows[0].Cells[1].Value.ToString();
            bool login = (bool)dgvUser.SelectedRows[0].Cells[2].Value;
            try
            {
                this.Cursor = Cursors.WaitCursor;

                frmUser f = new frmUser(frmUser.Mode.Modify);
                f.txtUsername.Text = username;
                f.cmbGroup.SelectedItem = group;
                f.chkLogin.Checked = login;
                if (username == QAController.Username)
                    f.cmbGroup.Enabled = false;

                f.ShowDialog();

                RefreshDataGridUser();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void dgvUser_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dgvUser.SelectedRows.Count > 0)
                btnUbah_Click(sender, e);
        }

        private void qaBaseDataGrid1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            btnDetail_Click(sender, e);
        }

        private void btnHapusJob_Click(object sender, EventArgs e)
        {
            if (dgvJob.SelectedRows.Count == 0)
            {
                MessageBox.Show("Tidak ada data yang dipilih", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //else if added by Vincent 20130204 for handling delete exception in copy all grid rows to excel---------------------
            else if (dgvJob.SelectedRows.Count > 1)
            {
                MessageBox.Show("Pilih hanya satu data yang akan dihapus", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //-------------------------------------------------------------------------------------------------------------------

            string msg = "Anda yakin akan menghapus job ini ?";
            if (MessageBox.Show(msg, this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.No)
                return;

            try
            {
                this.Cursor = Cursors.WaitCursor;
                List<QAJob> lstJob = new List<QAJob>();
                foreach (DataGridViewRow row in dgvJob.SelectedRows)
                {
                    string docId = row.Cells[0].Value.ToString();
                    string barcode = row.Cells[1].Value.ToString();
                    QAJob job = QAController.GetJobByDocIdAndBarcode(docId, barcode);
                    lstJob.Add(job);
                }

                if (QAController.DeleteJob(lstJob) != dgvJob.SelectedRows.Count)
                {
                    MessageBox.Show("Ada Petugas yang masih Online", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                } 
                PopulateDataGrid();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void btnGantiPetugas_Click(object sender, EventArgs e)
        {           
            try
            {
                this.Cursor = Cursors.WaitCursor;

                frmPetugas fp = new frmPetugas();
                if (fp.ShowDialog() == DialogResult.OK)
                {
                    frmPenugasan f = new frmPenugasan(frmPenugasan.Mode.Modify);
                    f.Text = " Ganti Petugas " + QAAdmin.Util.StringUtil.ConvertToString(fp.NamaPetugas) + " (" + QAController.TipeSPT.ToString() + ")";
                    List<QAJob> lstTemp = new List<QAJob>();
                    foreach (string s in fp.NamaPetugas)
                    {                        
                        List<QAJob> lstjob = new List<QAJob>(QAController.GetJobByPetugasAndStatus(s, "%"));
                        lstTemp.AddRange(lstjob);
                    }
                    f.ListJob = lstTemp;
                    f.ShowDialog();
                }                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void btnLogout_Click(object sender, EventArgs e)
        {
            QAController.UbahStatusLoginPetugas(0);
            this.Text = "QA Admin";
            Initialize();
        }

        private void btnRefreshReport_Click(object sender, EventArgs e)
        {
            if (dgvReportPenugasan.SelectedRows.Count == 0)
            {                
                return;
            }
            try
            {
                this.Cursor = Cursors.WaitCursor;
                dgvReport.AutoGenerateColumns = false;

                dgvReport.DataSource = null;
                dgvReport.Columns[0].DataPropertyName = "Username";
                dgvReport.Columns[1].DataPropertyName = "JumlahSPT";
                dgvReport.Columns[2].DataPropertyName = "JumlahPass";
                dgvReport.Columns[3].DataPropertyName = "JumlahHold";
                dgvReport.Columns[4].DataPropertyName = "JumlahSuspend";
                string jobId = dgvReportPenugasan.SelectedRows[0].Cells[0].Value.ToString();
                dgvReport.DataSource = QAController.GetListJobReport(jobId);
                dgvReport.Update();

                //--added by Vincent 20130110 for row number--
                //dgvReport.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders; 
                /*int rowNumber = 1;
                foreach (DataGridViewRow row in dgvReport.Rows)
                {
                    if (row.IsNewRow) continue;
                    row.HeaderCell.Value = "" + rowNumber;
                    rowNumber = rowNumber + 1;
                }
                dgvReport.RowHeadersWidth = 50;*/
                //dgvReport.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void btnUbahStatus_Click(object sender, EventArgs e)
        {
            if (dgvJob.SelectedRows.Count == 0)
            {
                MessageBox.Show("Tidak ada data yang dipilih", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //else if added by Vincent 20130204 for handling update exception in copy all grid rows to excel---------------------
            else if (dgvJob.SelectedRows.Count > 1)
            {
                MessageBox.Show("Pilih hanya satu data yang akan diubah", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //-------------------------------------------------------------------------------------------------------------------

            try
            {
                this.Cursor = Cursors.WaitCursor;
                string docId = dgvJob.SelectedRows[0].Cells[0].Value.ToString();
                string barcode = dgvJob.SelectedRows[0].Cells[1].Value.ToString();

                QAJob job = QAController.GetJobByDocIdAndBarcode(docId, barcode);
                QAController.Job = job;
                frmUbahStatus f = new frmUbahStatus();
                f.ShowDialog();
                btnRefresh_Click(sender, e);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void btnRefreshPenugasan_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                dgvReportPenugasan.AutoGenerateColumns = false;

                dgvReportPenugasan.DataSource = null;
                dgvReportPenugasan.Columns[0].DataPropertyName = "JobID";
                dgvReportPenugasan.Columns[1].DataPropertyName = "WaktuPenugasan";
                dgvReportPenugasan.Columns[2].DataPropertyName = "JumlahSPT";
                dgvReportPenugasan.Columns[3].DataPropertyName = "JumlahPerbaikan";
                dgvReportPenugasan.Columns[0].Visible = false;
                dgvReportPenugasan.DataSource = QAController.GetListJobReportPenugasan();
                dgvReportPenugasan.Update();

                //--added by Vincent 20130110 for row number--
                //dgvReportPenugasan.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders; 
                /*int rowNumber = 1;
                foreach (DataGridViewRow row in dgvReportPenugasan.Rows)
                {
                    if (row.IsNewRow) continue;
                    row.HeaderCell.Value = "" + rowNumber;
                    rowNumber = rowNumber + 1;
                }
                dgvReportPenugasan.RowHeadersWidth = 50;*/
                //dgvReportPenugasan.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void dgvReportPenugasan_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            btnRefreshReport_Click(sender, e);
        }

        private void tbpUser_Layout(object sender, LayoutEventArgs e)
        {
            btnRefreshUser_Click(sender, e);
        }

        private void btnPassHistory_Click(object sender, EventArgs e)
        {
            this.lblMonitor.Text = "Pass History";
            dgvJob.Rows.Clear();
            string petugas = string.Empty;
            string status = string.Empty;
            petugas = cmbPetugas.Text.Equals("all") ? "%" : cmbPetugas.Text;
            status = QAStatus.pass.ToString();
     
            lstQAJob = QAController.GetJobByPetugasAndStatus(petugas, status);

            foreach (QAJob job in lstQAJob)
            {
                string waktuPengecekan = job.StatusAkhir.Length == 0 ? "" : job.WaktuPengecekan.ToString("dd MMM yyyy HH:mm:ss");
                object[] values = { job.DocId, job.Barcode, job.JenisSPT, job.NamaPTKP, job.Npwp, job.MasaPajak, 
                                      job.WaktuPenugasan.ToString("dd MMM yyyy HH:mm:ss"), job.DitugaskanKepada, waktuPengecekan, job.StatusAkhir, job.Catatan, job.JumlahPerbaikan };
                dgvJob.Rows.Add(values);
            }

            //--added by Vincent 20130110 for row number--
            //dgvJob.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders; 
            /*int rowNumber = 1;
            foreach (DataGridViewRow row in dgvJob.Rows)
            {
                if (row.IsNewRow) continue;
                row.HeaderCell.Value = "" + rowNumber;
                rowNumber = rowNumber + 1;
            }
            dgvJob.RowHeadersWidth = 50;*/
            //dgvJob.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);  
        }

        protected override bool ProcessCmdKey(ref Message message, Keys keys)
        {
            switch (keys)
            {
                case Keys.F5:
                    //Process action here.
                    if (tabControl1.SelectedTab == tbpReport)
                    {
                        btnRefreshPenugasan_Click(new object(), new EventArgs());
                        btnRefreshReport_Click(new object(), new EventArgs());
                    }
                    else if (tabControl1.SelectedTab == tbpQAJob)                    
                        btnRefresh_Click(new object(), new EventArgs());                    
                    else if (tabControl1.SelectedTab == tbpUser)
                        btnRefreshUser_Click(new object(), new EventArgs());
                    break;
                case Keys.D | Keys.Control:
                    if (tabControl1.SelectedTab == tbpQAJob)                    
                        btnDetail_Click(new object(), new EventArgs());                    
                    break;
                case Keys.B | Keys.Control:
                    if (tabControl1.SelectedTab == tbpQAJob)
                        btnBuatPenugasan_Click(new object(), new EventArgs());
                    break;
                case Keys.U | Keys.Control:
                    if (tabControl1.SelectedTab == tbpQAJob)
                        btnUbahStatus_Click(new object(), new EventArgs());
                    else if (tabControl1.SelectedTab == tbpUser)
                        btnUbah_Click(new object(), new EventArgs());
                    break;
                case Keys.G | Keys.Control:
                    if (tabControl1.SelectedTab == tbpQAJob)
                        btnGantiPetugas_Click(new object(), new EventArgs());
                    break;
                case Keys.P | Keys.Control:
                    if (tabControl1.SelectedTab == tbpQAJob)
                        btnPassHistory_Click(new object(), new EventArgs());
                    break;
                case Keys.Delete:
                    if (tabControl1.SelectedTab == tbpQAJob)
                        btnHapusJob_Click(new object(), new EventArgs());
                    else if (tabControl1.SelectedTab == tbpUser)
                        btnHapus_Click(new object(), new EventArgs());
                    break;
                case Keys.T | Keys.Control:
                    if (tabControl1.SelectedTab == tbpUser)
                        btnTambah_Click(new object(), new EventArgs());
                    break;
                //added by Vincent 20130204 for shortcut log out
                case Keys.L | Keys.Control:
                    btnLogout.PerformClick();
                    break;
            }

            return false;
        }

        private void tbpReport_Enter(object sender, EventArgs e)
        {            
            btnRefreshPenugasan_Click(sender, e);            
        }

        private void dgvReportPenugasan_SelectionChanged(object sender, EventArgs e)
        {
            btnRefreshReport_Click(sender, e);
        }
    }
}
